<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>user admin</title>
        <link href="../../script/seminar.css" rel="stylesheet"/>
        <script type="text/javascript" src="../../js/jquery.js"></script>
        <script type="text/javascript" src="../../js/jquery.validate.min.js"></script>
        <script type="text/javascript" src="../../js/script.js"></script>
        <script type="text/javascript">
            function fnLogOut() {
                document.userAdminForm.method = 'POST';
                document.userAdminForm.action = '../../logic/logout.php';
                document.userAdminForm.submit();
            }
            function fnSlctUser() {
                var vIdxUser = document.getElementById("slctUser").selectedIndex;
                var vIdUser = document.getElementById("slctUser")[vIdxUser].value;
                document.userAdminForm.hidIdUser.value = vIdUser;
                document.userAdminForm.method = 'POST';
                document.userAdminForm.action = '../../logic/getDetilUserAdmin.php';
                document.userAdminForm.submit();
            }
            function fnSimpanUser() {
                // simpan perubahan
                // flag_simpan = 1 ==> hidUbah = 2, simpan perubahan
                // flag_simpan = null ==> hidUbah = null, tambah seminar
                var vFlagSimpan = document.getElementById("hidFlagSimpan").value;
                if (vFlagSimpan == '1') {
                    var vIdxUser = document.getElementById("slctUser").selectedIndex;
                    var vIdUser = document.getElementById("slctUser")[vIdxUser].value;
                    document.userAdminForm.hidIdUser.value = vIdUser;
                    document.userAdminForm.hidUbah.value = '2';
                    document.userAdminForm.method = 'POST';
                    document.userAdminForm.action = '../../logic/ubahUserAdmin.php';
                    document.userAdminForm.submit();
                } else {
                    document.userAdminForm.hidUbah.value = '';
                    document.userAdminForm.method = 'POST';
                    document.userAdminForm.action = '../../logic/addUserAdmin.php';
                    document.userAdminForm.submit();
                }
            }
            function fnUbahUser() {
                var vIdxUser = document.getElementById("slctUser").selectedIndex;
                var vIdUser = document.getElementById("slctUser")[vIdxUser].value;
                document.userAdminForm.hidIdUser.value = vIdUser;
                document.userAdminForm.hidUbah.value = '1';
                document.userAdminForm.method = 'POST';
                document.userAdminForm.action = '../../logic/ubahUserAdmin.php';
                document.userAdminForm.submit();
            }
            function fnHapusUser() {
                var vIdxUser = document.getElementById("slctUser").selectedIndex;
                var vIdUser = document.getElementById("slctUser")[vIdxUser].value;
                document.userAdminForm.hidIdUser.value = vIdUser;
                document.userAdminForm.method = 'POST';
                document.userAdminForm.action = '../../logic/hapusUserAdmin.php';
                document.userAdminForm.submit();
            }
            function fnChangeStsUser(vNoSeminar) {
                var vIdxUserGroup = document.getElementById("slctStsUser_" + vNoSeminar).selectedIndex;
                var vUserGroup = document.getElementById("slctStsUser_" + vNoSeminar)[vIdxUserGroup].value;
                //alert('vUserGroup: ' + vUserGroup);
                document.getElementById("hidUserGroup_" + vNoSeminar).value = vUserGroup;
            }
        </script>
    </head>
    <body>
        <?php
        include("../../utility/connection.php");
        include("../../utility/general.php");
        include("../../model/mUser.php");
        include("../../model/mSeminar.php");
        include("../../model/mUserSeminar.php");
        session_start();
        if (isset($_SESSION['arrResult'])) {
            $arrResult = $_SESSION['arrResult'];
        ?>
        <form name="userAdminForm" id="userAdminForm">
        <input type="hidden" name="hidIdUser" id="hidIdUser">
        <input type="hidden" name="hidUbah" id="hidUbah">
        <input type="hidden" name="hidStsSeminar" id="hidStsSeminar">
        <table border="0" width="100%" height="100%">
            <tr valign="middle">
                <td align="center">
                    
                    <table width="90%" border="0" cellpadding="2" cellspacing="0">
                        <tr class="tbl-body">
                            <td width="25%">
                                <table width="100%" border="0" cellpadding="5" cellspacing="0">
                                    <tr class="tbl-header">
                                        <td>DAFTAR&nbsp;USER</td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <select name="slctUser" id="slctUser" onchange="fnSlctUser()" style="width: 200px" size="18">
                                                <?php
                                                $userId = '';
                                                if (isset($_SESSION['userId'])) {
                                                    $userId = $_SESSION['userId'];
                                                }
                                                
                                                $resultAllUser = fnSelectAllUser();
                                                if ($resultAllUser) {
                                                    while($rowUser = mysql_fetch_row($resultAllUser)){
                                                ?>
                                                <option value="<?php echo $rowUser[0] ?>" <?php echo ($userId == $rowUser[0])? 'SELECTED':'' ?>><?php echo $rowUser[1] ?>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </select>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="75%">
                                <table width="100%" height="100%" border="0" cellpadding="5" cellspacing="0">
                                    <tr class="tbl-header">
                                        <td colspan="3">DETIL&nbsp;USER</td>
                                    </tr>
                                    <?php
                                    if (isset($_SESSION['userResult'])) {
                                        $userSeminar = $_SESSION['userResult'];
                                        $UserId = $userSeminar[0];
                                    ?>
                                    <tr class="tbl-body">
                                        <td>Nama</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[1] ?></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Alamat</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[2] ?></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Kota</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[3] ?></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Propinsi</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[4] ?></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Negara</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[5] ?></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Kode&nbsp;Pos</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[6] ?></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Telepon</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[7] ?></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Email</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[8] ?></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>User&nbsp;Name</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[9] ?></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Password</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="80%"><?php echo $userSeminar[10] ?></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr class="tbl-body">
                            <td colspan="2">
                                <table width="100%" height="100%" border="1" cellpadding="5" cellspacing="0">
                                    <tr class="tbl-header">
                                        <td>No</td>
                                        <td width="50%">Tema</td>
                                        <td>Tanggal</td>
                                        <td>Status&nbsp;User</td>
                                    </tr>
                                    <?php
                                    $resultUserAllSeminar = fnUserAllSeminar($UserId);
                                    if ($resultUserAllSeminar) {
                                        $num = 1;
                                        while($rowUser = mysql_fetch_row($resultUserAllSeminar)){
                                            $tglOrig = $rowUser[4];
                                            $digitTgl = substr($tglOrig,-2,2);
                                            $digitBulan = fnConvertMonth(substr($tglOrig,-5,2));
                                            $digitTahun = substr($tglOrig,0,4);
                                    ?>
                                    <tr>
                                        <td align="center"><?php echo $num ?></td>
                                        <td><?php echo $rowUser[1] ?></td>
                                        <td align="center"><?php echo $digitTgl ?>&nbsp;<?php echo $digitBulan ?>&nbsp;<?php echo $digitTahun ?></td>
                                        <td align="center"><?php echo $rowUser[11] ?></td>
                                    </tr>
                                    <?php
                                        $num = $num + 1;
                                        }
                                    }
                                    ?>
                                </table>
                            </td>
                        </tr>
                        <tr class="tbl-body">
                            <td colspan="3">
                                <button type="button" name="btUbah" id="btUbah" onclick="fnUbahUser()">Ubah</button>
                                <button type="button" name="btHapus" id="btHapus" onclick="fnHapusUser()">Hapus</button>
                            </td>
                        </tr>
                        <?php 
                        }
                        ?>
                        <tr class="tbl-body">
                            <td colspan="2">
                                <table width="100%" border="0" cellpadding="5" cellspacing="0">
                                    <tr class="tbl-header">
                                        <td colspan="3">TAMBAH&nbsp;USER</td>
                                    </tr>
                                    <?php
                                    $dummyFlag = 1;
                                    $Nama = '';
                                    $Alamat = '';
                                    $Kota = '';
                                    $Propinsi = '';
                                    $Negara = '';
                                    $KodePos = '';
                                    $Telp = '';
                                    $Email = '';
                                    $LoginId = '';
                                    $Password = '';
                                    $FlagSimpan = '';
                                    if ($dummyFlag == 1) {
                                        if (isset($_SESSION['ubah'])) {
                                            $FlagSimpan = $_SESSION['ubah'];
                                            $ubahUser = $_SESSION['ubahUser'];
                                            $_SESSION['slctUser'] = $ubahUser[0];
                                            $Nama = $ubahUser[1];
                                            $Alamat = $ubahUser[2];
                                            $Kota = $ubahUser[3];
                                            $Propinsi = $ubahUser[4];
                                            $Negara = $ubahUser[5];
                                            $KodePos = $ubahUser[6];
                                            $Telp = $ubahUser[7];
                                            $Email = $ubahUser[8];
                                            $LoginId = $ubahUser[9];
                                            $Password = $ubahUser[10];
                                        }
                                    ?>
                                    <tr class="tbl-body">
                                        <td>Nama</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtNama" id="txtNama" size="50" maxlength="30" value="<?php echo $Nama ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Alamat</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtAlamat" id="txtAlamat" size="50" maxlength="255" value="<?php echo $Alamat ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Kota</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtKota" id="txtKota" size="50" maxlength="30" value="<?php echo $Kota ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Propinsi</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtPropinsi" id="txtPropinsi" size="50" maxlength="30" value="<?php echo $Propinsi ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Negara</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtNegara" id="txtNegara" size="50" maxlength="30" value="<?php echo $Negara ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Kode&nbsp;Pos</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtKodePos" id="txtKodePos" size="50" maxlength="10" value="<?php echo $KodePos ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>No&nbsp;Telp</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtTelp" id="txtTelp" size="50" maxlength="20" value="<?php echo $Telp ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Email</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtEmail" id="txtEmail" size="50" maxlength="30" value="<?php echo $Email ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Login&nbsp;ID</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtLoginId" id="txtLoginId" size="50" maxlength="30" value="<?php echo $LoginId ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td>Password</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td><input type="text" name="txtPassword" id="txtPassword" size="50" maxlength="30" value="<?php echo $Password ?>"></td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td colspan="3">
                                            <table width="100%" height="100%" border="1" cellpadding="5" cellspacing="0">
                                                <tr class="tbl-header">
                                                    <td>No</td>
                                                    <td width="50%">Tema</td>
                                                    <td>Tanggal</td>
                                                    <td>Status&nbsp;User</td>
                                                </tr>
                                                <?php
                                                $resultAllSeminar = fnSelectAllSeminar();
                                                $JmlSeminar = mysql_num_rows($resultAllSeminar);
                                                if ($resultAllSeminar) {
                                                    $num = 1;
                                                    while($rowAllSeminar = mysql_fetch_row($resultAllSeminar)){
                                                        $SeminarId = $rowAllSeminar[0];
                                                        $tglOrig1 = $rowAllSeminar[4];
                                                        $digitTgl1 = substr($tglOrig1,-2,2);
                                                        $digitBulan1 = fnConvertMonth(substr($tglOrig1,-5,2));
                                                        $digitTahun1 = substr($tglOrig1,0,4);
                                                ?>
                                                <tr>
                                                    <td align="center">
                                                        <?php echo $num ?>
                                                        <input type="hidden" name="hidIdSeminar_<?php echo $num ?>" id="hidIdSeminar_<?php echo $num ?>" value="<?php echo $SeminarId ?>">
                                                    </td>
                                                    <td><?php echo $rowAllSeminar[1] ?></td>
                                                    <td align="center"><?php echo $digitTgl1 ?>&nbsp;<?php echo $digitBulan1 ?>&nbsp;<?php echo $digitTahun1 ?></td>
                                                    <td align="center">
                                                        <select name="slctStsUser_<?php echo $num ?>" id="slctStsUser_<?php echo $num ?>" onchange="fnChangeStsUser(<?php echo $num ?>)">
                                                            <option value="0"></option>
                                                            <?php
                                                            $UserGroup = 0;
                                                            if (isset($_SESSION['slctUser'])) {
                                                                $UserId1 = $_SESSION['slctUser'];
                                                                $resultUserOnSeminar = fnUserOnSeminar($UserId1, $SeminarId);
                                                                $arrUserOnSeminar = mysql_fetch_array($resultUserOnSeminar);
                                                                $UserGroup = $arrUserOnSeminar[10];
                                                            }
                                                            
                                                            $resultAllUserGroup = fnSelectAllUserGroup();
                                                            if ($resultAllUserGroup) {
                                                                while($rowAllUserGroup = mysql_fetch_row($resultAllUserGroup)){
                                                             ?>
                                                            <option value="<?php echo $rowAllUserGroup[0] ?>" <?php echo ($rowAllUserGroup[0] == $UserGroup)?"SELECTED":""?>><?php echo $rowAllUserGroup[1] ?></option>
                                                            <?php
                                                                }
                                                            }
                                                            ?>
                                                        </select>
                                                        <input type="text" style="display: none;" size="3" name="hidUserGroup_<?php echo $num ?>" id="hidUserGroup_<?php echo $num ?>" value="<?php echo $UserGroup ?>" >
                                                    </td>
                                                </tr>
                                                <?php
                                                    $num = $num + 1;
                                                    }
                                                }
                                                ?>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr class="tbl-body">
                                        <td colspan="3">
                                            <input type="hidden" name="hidFlagSimpan" id="hidFlagSimpan" value="<?php echo $FlagSimpan ?>">
                                            <input type="hidden" name="hidJmlSeminar" id="hidJmlSeminar" value="<?php echo $JmlSeminar ?>">
                                            <button type="button" name="btSimpan" id="btSimpan" onclick="fnSimpanUser()">Simpan</button>
                                        </td>
                                    </tr>
                                     <?php
                                    }
                                    ?>
                                    
                                </table>
                            </td>
                        </tr>
                    </table>
                    
                </td>
            </tr>
<!--            <tr valign="middle">
                <td align="center">
                    <button type="button" name="btLogOut" id="btLogOut" onclick="fnLogOut()">LogOut</button>
                </td>
            </tr>-->
        </table>
        </form>
        <?php
        }
        ?>
    </body>
</html>
